@node Basic thread operations
@section Basic thread operations

@stindex threads
This section describes the @code{threads} structure.

@cindex spawning threads
@cindex threads, spawning
@deffn procedure spawn thunk [name] @returns{} thread
@code{Spawn} constructs a new thread and instructs the current thread
scheduler to commence running the new thread.  @var{Name}, if present,
is used for debugging.  The new thread has a fresh
@embedref{Fluid/dynamic bindings, dynamic environment}.
@end deffn

There are several miscellaneous facilities for thread operations.

@cindex yielding threads
@cindex thread yielding
@cindex sleeping threads
@cindex thread sleeping
@deffn procedure relinquish-timeslice @returns{} unspecified
@deffnx procedure sleep count @returns{} unspecified
@code{Relinquish-timeslice} relinquishes the remaining quantum that the
current thread has to run; this allows the current scheduler run the
next thread immediately.  @code{Sleep} suspends the current thread for
@var{count} milliseconds.
@end deffn

@cindex thread termination
@cindex terminating threads
@deffn procedure terminate-current-thread @returns{} (does not return)
Terminates the current thread, running all @code{dynamic-wind} exit
points.  @code{Terminate-current-thread} obviously does not return.
@end deffn

@cindex thread descriptors
Threads may be represented and manipulated in first-class thread
descriptor objects.

@deffn procedure current-thread @returns{} thread
@deffnx procedure thread? object @returns{} boolean
@deffnx procedure thread-name thread @returns{} value
@deffnx procedure thread-uid thread @returns{} unique-integer-id
@code{Current-thread} returns the thread descriptor for the currently
running thread.  @code{Thread?} is the thread descriptor disjoint type
predicate.  @code{Thread-name} returns the name that was passed to
@code{spawn} when spawning @var{thread}, or @code{#f} if no name was
passed.  @code{Thread-uid} returns a thread descriptor's unique integer
identifier, assigned by the thread system.
@end deffn
